package com.example.cxx.myapplication;

import android.animation.Animator;
import android.animation.ObjectAnimator;
import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AlphaAnimation;
import android.view.animation.AnimationSet;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;

import java.util.ArrayList;
import java.util.List;


public class SecondFragment extends Fragment {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_second, container, false);
    }

    @Override
    public void onResume() {
        super.onResume();

        PickerView pickView = (PickerView) getView().findViewById(R.id.picker);
        List<String> data = new ArrayList<String>();
        for (int i = 0; i < 110; i++)
        {
            data.add("" + (i+1900));
        }
        pickView.setData(data);
        pickView.setSelected(90);
        final ProgressBar progressBar = (ProgressBar) getView().findViewById(R.id.progress);
        final ImageView spot = (ImageView) getView().findViewById(R.id.spot);

        float height = progressBar.getWidth();
        ViewGroup.MarginLayoutParams marginLayoutParams = new ViewGroup.MarginLayoutParams(spot.getLayoutParams());
        marginLayoutParams.setMargins(100, 0, 0, 0);
        RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(marginLayoutParams);

        spot.setLayoutParams(layoutParams);
        AlphaAnimation alphaAnimation = new AlphaAnimation(0.0f,1.0f);

        AnimationSet animatorSet = new AnimationSet(true);

        animatorSet.addAnimation(alphaAnimation);
        animatorSet.setDuration(1000);
        spot.setAnimation(animatorSet);

        progressBar.setMax(100);
        ObjectAnimator objectAnimator =  ObjectAnimator.ofInt(progressBar,"progress"
                , 0, 50);
        objectAnimator.setDuration(1000);
        objectAnimator.setStartDelay(5000);
        objectAnimator.start();

//        progressBar.setProgress(50);
    }

}
